package com.isoft.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.isoft.dao.AirportChangedao;
import com.isoft.entity.AirportChange;
import com.isoft.entity.PageBean;
import com.isoft.service.IAirportChangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class AirportChangeService implements IAirportChangeService {
    @Autowired
     AirportChangedao airportChangedao;
    @Override
    public PageBean getAll(Integer page , Integer pageSize) {
        //1.设置分页参数
        PageHelper.startPage(page, pageSize);
        //2.执行查询
        List<AirportChange> airportChangeList = airportChangedao.getAll();
        Page<AirportChange> p = (Page<AirportChange>) airportChangeList;
        //3.封装PageBean对象
        PageBean pageBean = new PageBean((int) p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public PageBean getByCons(Integer page, Integer pageSize, String cnnm,String frcd) {
        PageHelper.startPage(page, pageSize);
        List<AirportChange> airportChangeList = airportChangedao.getByCons(cnnm,frcd);
        Page<AirportChange> p = (Page<AirportChange>) airportChangeList;
        PageBean pageBean = new PageBean((int) p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public Boolean changePermit(Integer id) {
        return airportChangedao.changePermit(id)>0;
    }

    @Override
    public Boolean deleteChange(Integer id) {
        return airportChangedao.deleteChange(id)>0;
    }

    @Override
    public Boolean addChange(AirportChange airportChange) {
        airportChange.setIspermit(0);
        return airportChangedao.addChange(airportChange) > 0;
    }

    @Override
    public Boolean updateChange(AirportChange airportChange) {
        airportChange.setIspermit(0);
        return airportChangedao.updateChange(airportChange)>0;
    }

    @Override
    public List<AirportChange> unPermit() {
        return airportChangedao.unPermit();
    }




}
